{% extends "base.html" %}
{% load difftags %}
{% load djblets_deco %}
{% load djblets_utils %}
{% load i18n %}
{% load reviewtags %}

{% block title %}{{review_request_details.summary}} | {% trans "Diff Viewer" %}{% endblock %}

{% block jsconsts %}
{% include "reviews/review_flags.js" %}
  var gRevision = '{{diffset.revision}}';
{% if interdiffset %}
  var gInterdiffRevision = '{{interdiffset.revision}}';
{% else %}
  var gInterdiffRevision = null;
{% endif %}
{% endblock %}

{% block css %}
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/diffviewer.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/reviews.css?{{MEDIA_SERIAL}}" />
<link rel="stylesheet" type="text/css" href="{{MEDIA_URL}}rb/css/syntax.css?{{MEDIA_SERIAL}}" />
{% if siteconfig.settings.diffviewer_show_trailing_whitespace %}
<style type="text/css">
  .ew { background: #ee3434; }
</style>
{% endif %}
{% endblock %}

{% block scripts %}
<script type="text/javascript" src="{{MEDIA_URL}}djblets/js/jquery-1.3.1.min.js"></script>
{% endblock %}

{% block scripts-post %}
<script type="text/javascript" src="{{MEDIA_URL}}djblets/js/jquery-ui-1.6rc5.min.js"></script>
<script type="text/javascript" src="{{MEDIA_URL}}djblets/js/jquery.gravy.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/ui.autocomplete.min.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/common.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/diffviewer.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/reviews.js?{{MEDIA_SERIAL}}"></script>
<script type="text/javascript" src="{{MEDIA_URL}}rb/js/jquery.form.js?{{MEDIA_SERIAL}}"></script>
{% endblock %}

{% block content %}
{% if error %}
{%  errorbox %}
<p>{{error}}</p>
{%   if trace %}<pre>{{trace|escape}}</pre>{% endif %}
{%  enderrorbox %}
{% else %}{# !error #}

{% include "reviews/trophy_box.html" %}
{% include "reviews/review_header.html" %}

{% box "review-request" %}
<ul id="actions">
{% include "reviews/review_request_actions_secondary.html" %}
 <li class="primary"><a href="raw/">{% trans "Download Diff" %}</a></li>
{% include "reviews/review_request_actions_primary.html" %}
 <li class="primary"><a href="{{review_request.get_absolute_url}}">{% trans "View Reviews" %}</a></li>
</ul>
<div class="main">
{% include "reviews/review_request_box.html" %}

<div id="diff-details">
<a name="index_header"></a>
{% with review_request.diffset_history.diffsets.latest.revision as latest_revision %}
{% with diffset.revision as revision %}
<div class="main">
{%  if interdiffset %}
{#   We're showing an interdiff, so indicate the revision range. #}
 <h1>{% blocktrans with interdiffset.revision as interdiff_revision %}Changes between revision {{revision}} and {{interdiff_revision}}{% endblocktrans %}</h1>
{%  else %}
{%   ifequal diffset.revision latest_revision %}
 <h1>{% blocktrans %}Diff revision {{revision}} (Latest){% endblocktrans %}</h1>
{%   else %}
{#    This is not the most recent diff. See if we're showing a draft. #}
{%    if is_draft_diff %}
 <h1>{% trans "Draft diff" %}</h1>
 <p>
{%     blocktrans %}
  This diff is part of your current draft. Other users will not see this
  diff until you publish your draft.
{%     endblocktrans %}
{%    else %}
{#     This is not a draft. Tell the user this is not the most recent. #}
 <h1>{% blocktrans %}Diff revision {{revision}}{% endblocktrans %}</h1>
 <p>
{%     blocktrans with diffset.revision as revision and review_request.get_absolute_url as review_request_url%}
  This is not the most recent revision of the diff. The
  <a href="{{review_request_url}}diff/">latest diff</a> is revision
  {{latest_revision}}.
  <a href="{{review_request_url}}diff/{{revision}}-{{latest_revision}}/">See what's changed.</a>
{%     endblocktrans %}
{%    endif %}
 </p>
{%   endifequal %}
{%  endif %}

{#  Notify the user if they have unpublished comments in other diffs. #}
{%  if review|has_comments_in_diffsets_excluding:diffset_pair %}
{%   box "important" %}
 <h1>{% trans "You have unpublished comments on other revisions" %}</h1>
 <p>
  {% trans "Your review consists of comments on the following revisions:" %}
 </p>
 <ul>
{%    for diffset_info in review|diffsets_with_comments:diffset_pair %}
{%     if diffset_info.is_current %}
  <li><b>Revision {{diffset_info.diffset.revision}}</b></li>
{%     else %}
  <li><a href="{{review_request.get_absolute_url}}diff/{{diffset_info.diffset.revision}}/#index_header">Revision {{diffset_info.diffset.revision}}</a></li>
{%     endif %}
{%    endfor %}
{%    for pair in review|interdiffs_with_comments:diffset_pair %}
{%     if pair.is_current %}
  <li><b>Interdiff revision {{pair.diffset.revision}} - {{pair.interdiff.revision}}</b></li>
{%     else %}
  <li><a href="{{review_request.get_absolute_url}}diff/{{pair.diffset.revision}}-{{pair.interdiff.revision}}/">Interdiff revision {{pair.diffset.revision}} - {{pair.interdiff.revision}}</a></li>
{%     endif %}
{%    endfor %}
 </ul>
 {%  endbox %}
{%  endif %}

{%  ifnotequal num_diffs 1 %}
{#   Show a revision selector for jumping between revisions. #}
 <table class="revision-selector">
  <tr>
   <th><label for="jump_to_revision">{% trans "Jump to revision:" %}<label></th>
   <td>
    <div id="jump_to_revision" class="revisions">
{%  for item in review_request.diffset_history|revision_link_list:diffset_pair %}
{%   if item.is_current %}
     <span class="current">{{item.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{item.revision}}/#index_header">{{item.revision}}</a>
{%   endif %}
{%  endfor %}
{%  if draft and draft.diffset %}
{#   There's a draft diff, so display it in the list. #}
{%   if is_draft_diff %}
     <span class="current">{{draft.diffset.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{draft.diffset.revision}}/#index_header">{{draft.diffset.revision}}</a>
{%   endif %}
{%  endif %}
    </div>
   </td>
  </tr>
  <tr>
   <th><label for="show_interdiff">{% blocktrans %}Changes between r{{revision}} and:{% endblocktrans %}</label></th>
   <td>
    <div id="show_interdiff" class="revisions">
{%  for item in review_request.diffset_history|interdiff_link_list:diffset_pair %}
{%   if item.is_current %}
     <span class="current">{{item.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{item.path}}/#index_header">{{item.revision}}</a>
{%   endif %}
{%  endfor %}
{%  if draft and draft.diffset %}
{#   There's a draft diff, so display it in the list. #}
{%   if is_draft_diff or is_draft_interdiff %}
     <span class="current">{{draft.diffset.revision}}</span>
{%   else %}
     <a href="{{review_request.get_absolute_url}}diff/{{diffset_pair.0}}-{{diffset_pair.1}}/#index_header">{{draft.diffset.revision}}</a>
{%   endif %}
{%  endif %}
    </div>
   </td>
  </tr>
 </table>
{% endifnotequal %}

 <p><label>{% trans "Files Changed:" %}</label></p>
{% include "diffviewer/changeindex.html" %}
  </div>
 </div>
</div>

<ul class="controls">
{% if collapseall %}
 <li><a href=".?expand=1"><img src="{{MEDIA_URL}}rb/images/expand.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Expand changes" %}</a></li>
{% else %}
 <li><a href=".?collapse=1"><img src="{{MEDIA_URL}}rb/images/collapse.png?{{MEDIA_SERIAL}}" width="14" height="14" border="0" alt="" /> {% trans "Collapse changes" %}</a></li>
{% endif %}
</ul>
{% endwith %}
{% endwith %}
{%  endbox %}

<div id="diffs">
{% for file in files %}
{%  if not interdiffset or file.interfilediff %}
{%   if file.fragment %}
{{file.fragment}}
{%   else %}
<table class="sidebyside loading{% if file.newfile %} newfile{% endif %}"
       id="file_container_{{file.filediff.id}}">
 <thead>
  <tr>
   <th colspan="2">{{file.depot_filename}}</th>
  </tr>
  <tr>
   <th class="rev">{{file.revision}}</th>
   <th class="rev">{{file.dest_revision}}</th>
  </tr>
 </thead>
 <tbody>
  <tr><td colspan="2"><pre>&nbsp;</pre></th></tr>
 </tbody>
</table>
{%   endif %}
<script type="text/javascript">
  $(document).ready(function() {
  loadFileDiff("{{file.filediff.id}}", "{{file.filediff.diffset.revision}}",
{% if file.interfilediff %}
               "{{file.interfilediff.id}}", "{{file.interfilediff.diffset.revision}}",
{% else %}
               null, null,
{% endif %}
               "{{file.index}}",
			   {% commentcounts file.filediff file.interfilediff %});
});
</script>
{%  endif %}
{% endfor %}

<a name="index_footer"></a>
{% include "diffviewer/changeindex.html" %}
</div>

{% include "reviews/comments_dlg.html" %}

{% endif %}{# !error #}
{% endblock %}
